Below is an example of how to create a system tray icon in a Windows Application (WinForms) using c# and vb.NET.
Here are the steps to follow to complete this tutorial.
Step 1
Create a windows form application
Step 2
Add a NotifyIcon to the main form
Step 3
Add an icon to the NotifyIcon
Note: it’s vital to add an icon to the NotifyIcon. Otherwise, the NotifyIcon will not show up.
Step 4
Add the code below to the Form Load event
C#
private void frm_Load(object sender, EventArgs e) { notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; notifyIcon1.BalloonTipText = "Welcome to TutorialsPanel.com!!"; notifyIcon1.BalloonTipTitle = "Welcome Message"; notifyIcon1.ShowBalloonTip(2000); }
VB.NET
Private Sub frm_Load(sender As Object, e As EventArgs) notifyIcon1.BalloonTipIcon = ToolTipIcon.Info notifyIcon1.BalloonTipText = "Welcome to TutorialsPanel.com!!" notifyIcon1.BalloonTipTitle = "Welcome Message" notifyIcon1.ShowBalloonTip(2000) End Sub
Step 5
Run the application
Step 6
Now let add a Double Click event on the NotifyIcon. Double click on the NotifyIcon in the design view, and then add the code below to the event
C#
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { MessageBox.Show("Someone just double clicked on the icon!"); notifyIcon1.Visible = false; }
VB.NET
Private Sub notifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) MessageBox.Show("Someone just double clicked on the icon!") notifyIcon1.Visible = False End Sub
Step 7
Double Click on the icon in the system tray
Comments
Thanks for the tutorial.
So can you show the tray icon when the form minimizes?
Try the resize event frm_Resize instead of frm_Load